import Vue, { KeepAlive } from 'vue'
import VueRouter from 'vue-router'
import Home from '../views/Home.vue'

Vue.use(VueRouter)

const routes = [
  {
    path: '/',
    redirect:"/home"
  },
  {
     path:"/home",
     name: 'Home',
    component: Home,
    meta:{ //自定义一些key和value 去使用
      // 在当前页面 可以获取到 自定义的信息
        KeepAlive:true
    }
  },
  {
    path:"/cart",
    name:"cart",
    // 路由独享钩子
    beforeEnter(to,from,next){
       console.log(to,from,"路由独享钩子")
       next();
    },
    component:()=>import("../views/Cart.vue"),
    meta:{
      KeepAlive:true,
      isLogin:true //需要登陆
    }
  },
  { 
    path:"/pay",
    name:"pay",
    meta:{
      isLogin:false
    },
    component:()=>import("../views/pay.vue")
  },
   { 
    path:"/login",
    name:"login",
    component:()=>import("../views/Login.vue")
  },
    { 
    path:"/temp",
    name:"temp",
    // alias:"mytemp",//路由的别名
    // redirect:"/cart",//重定向到其他页面
    meta:{ //自定义的信息
      KeepAlive:false
    },
    // children:[],
    // beforeEnter(){},//路由独享的钩子函数
    component:()=>import("../views/Temp.vue")
  },
  { 
    path:"/mymap",
    name:"mymap",
    component:()=>import("../views/myMap.vue")
  },
  { 
    path:"/product",
    name:"product",
    component:()=>import("../views/product.vue")
  },
  { 
    path:"/eleui",
    name:"eleui",
    component:()=>import("../views/eleui.vue")
  },
  {
    path:"/mine",
    name:"mine",
    component:()=>import("../views/Mine.vue")
  },
  { //关于页面的子路由
    path: '/about',
    name: 'About',

    component: () => import('../views/About.vue'),
    // 子路由的配置项
    children:[
      {
        // 子路由的path 不加/
        path:"aboutone",
        name:"aboutone",
        component:()=>import("../views/AboutOne.vue")
      },
      {
          path:"abouttwo",
         name:"abouttwo",
         component:()=>import("../views/AboutTwo.vue")
      }
    ]
  }
]

const router = new VueRouter({
  mode: 'history',
  base: process.env.BASE_URL,
  routes
})

export default router
